<!--客户信息-->
<template>
  <div class="app-container erha-content">
    <div class="erha-header">
      <el-form :inline="true" :model="queryForm" class="demo-form-inline">
        <el-form-item>
          <el-input v-model="queryForm.userName" clearable placeholder="客户名称" />
        </el-form-item>
        <el-form-item>
          <el-select v-model="queryForm.userType" clearable placeholder="客户类型">
            <el-option label="企业" value="企业" />
            <el-option label="个人" value="个人" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="queryTable">查询</el-button>
          <el-button type="primary" @click="openAddDialog()">新增</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="erha-body">
      <el-table
        :data="table.data"
        height="600"
        style="width: 100%;"
      >
        <el-table-column prop="userName" label="客户名称" min-width="180" />
        <el-table-column prop="userType" label="客户类型" min-width="180" />
        <el-table-column prop="idNumber" label="客户身份证" min-width="180" />
        <el-table-column prop="phoneCode" label="联系电话" min-width="180" />
        <el-table-column prop="userAddress" label="联系地址" min-width="180" />
        <el-table-column prop="userScore" label="评级" min-width="180">
          <template v-slot="{row}">
            <el-tag v-if="row.userScore > 90" effect="dark" type="success">一级({{ row.userScore }})分</el-tag>
            <el-tag v-else-if="row.userScore >= 80 && row.userScore <= 90" effect="dark">二级({{ row.userScore }})分</el-tag>
            <el-tag v-else-if="row.userScore && row.userScore < 80" effect="dark" type="warning">三级({{ row.userScore }})分</el-tag>
            <el-tag v-else type="info" effect="dark">未评分</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="userStatus" label="状态" min-width="180">
          <template v-slot="{row}">
            <el-tag v-if="row.userStatus == '0'" effect="dark" type="warning">未审核</el-tag>
            <el-tag v-if="row.userStatus == '1'" effect="dark" type="success">已审核</el-tag>
            <el-tag v-if="row.userStatus == '2'" effect="dark" type="info">未通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="contractStatus" label="合同" min-width="180">
          <template v-slot="{row}">
            <el-tag v-if="row.contractStatus == '1'" effect="dark" type="success">已签订</el-tag>
            <el-tag v-else effect="dark" type="warning">未签订</el-tag>
          </template>
        </el-table-column>

        <el-table-column label="操作" min-width="200">
          <template v-slot="{row}">
            <!--未审核-->
            <template v-if="row.userStatus === '0'">
              <el-button type="text" @click="openAddDialog(row)">编辑客户</el-button>

              <el-button type="text" @click="examine(row)">审核资质</el-button>
            </template>

            <!--已审核-->
            <template v-else>
              <el-button type="text" @click="openAddDialog(row, false)">查看客户</el-button>

              <!--审核通过-->
              <template v-if="row.userStatus === '1'">
                <!--未签订合同-->
                <template v-if="row.contractStatus === '0'">
                  <el-button type="text" @click="openContractDialog(row, false)">签订合同</el-button>
                </template>
                <!--已签订合同-->
                <template v-else>
                  <el-button type="text" @click="openContractDialog(row, true)">查看合同</el-button>
                  <el-button type="text" @click="openContractDialog(row, false)">编辑合同</el-button>
                </template>
              </template>

            </template>
          </template>
        </el-table-column>

      </el-table>
    </div>

    <!--新增/编辑弹窗-->
    <el-dialog
      :close-on-click-modal="false"
      :title="dialog.add.title"
      :visible.sync="dialog.add.show"
      width="800px"
    >
      <el-form ref="form" :model="dialog.add.form" label-width="120px">
        <el-tabs tab-position="left" style="height: 400px">
          <el-tab-pane label="客户实名信息">
            <el-scrollbar style="height: 400px;">
              <el-form-item label="客户类型">
                <el-select
                  v-model="dialog.add.form.userType"
                  class="width-90"
                  placeholder="请选择客户类型"
                  @change="changeCustomerType"
                >
                  <el-option label="企业" value="企业" />
                  <el-option label="个人" value="个人" />
                </el-select>
              </el-form-item>

              <el-form-item :label="`${customerType}名称`">
                <el-input
                  v-model="dialog.add.form.userName"
                  class="width-90"
                  clearable
                  :placeholder="`${customerType}名称`"
                />
              </el-form-item>

              <el-form-item :label="`${customerType}身份证`">
                <el-input
                  v-model="dialog.add.form.idNumber"
                  class="width-90"
                  clearable
                  :placeholder="`${customerType}身份证`"
                />
              </el-form-item>

              <el-form-item label="联系电话">
                <el-input v-model="dialog.add.form.phoneCode" class="width-90" clearable placeholder="联系电话" />
              </el-form-item>

              <el-form-item label="联系地址">
                <el-input v-model="dialog.add.form.userAddress" class="width-90" clearable placeholder="联系地址" />
              </el-form-item>

            </el-scrollbar>
          </el-tab-pane>

          <el-tab-pane label="客户基本信息">
            <el-scrollbar style="height: 400px;">
              <el-form-item label="年龄">
                <el-select v-model="dialog.add.form.userInfoProperty.age" class="width-90" placeholder="请选择客户年龄">
                  <el-option label="30~50" value="90" />
                  <el-option label="30岁以下" value="80" />
                  <el-option label="50岁以上" value="75" />
                </el-select>
              </el-form-item>

              <el-form-item label="学历">
                <el-select v-model="dialog.add.form.userInfoProperty.education" class="width-90" placeholder="请选择客户学历">
                  <el-option label="中专" value="80" />
                  <el-option label="大学" value="90" />
                  <el-option label="大学以上" value="95" />
                </el-select>
              </el-form-item>

              <el-form-item label="健康状况">
                <el-select v-model="dialog.add.form.userInfoProperty.health" class="width-90" placeholder="请选择健康状况">
                  <el-option label="健康" value="90" />
                  <el-option label="亚健康" value="80" />
                  <el-option label="其他" value="70" />
                </el-select>
              </el-form-item>

              <el-form-item label="住房情况">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.HousingSituation"
                  class="width-90"
                  placeholder="请选择住房情况"
                >
                  <el-option label="自有" value="95" />
                  <el-option label="租赁" value="85" />
                  <el-option label="其他" value="70" />
                </el-select>
              </el-form-item>

              <el-form-item label="单位类别">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.unitCategory"
                  class="width-90"
                  placeholder="请选择单位类别"
                >
                  <el-option label="行政事业" value="90" />
                  <el-option label="规模化企业" value="80" />
                  <el-option label="不详" value="75" />
                </el-select>
              </el-form-item>

              <el-form-item label="单位工龄">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.workingYears"
                  class="width-90"
                  placeholder="请选择单位工龄"
                >
                  <el-option label="10年以上" value="90" />
                  <el-option label="10年以下" value="80" />
                  <el-option label="不详" value="75" />
                </el-select>
              </el-form-item>

              <el-form-item label="婚姻状况">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.maritalStatus"
                  class="width-90"
                  placeholder="请选择婚姻状况"
                >
                  <el-option label="已婚" value="90" />
                  <el-option label="未婚" value="80" />
                  <el-option label="其他" value="70" />
                </el-select>
              </el-form-item>
            </el-scrollbar>
          </el-tab-pane>

          <el-tab-pane label="客户经营情况">
            <el-scrollbar style="height: 400px;">
              <el-form-item label="从事产业">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.engageIndustry"
                  class="width-90"
                  placeholder="请选择从事产业"
                >
                  <el-option label="稳定型" value="90" />
                  <el-option label="发展型" value="85" />
                  <el-option label="其他" value="75" />
                </el-select>
              </el-form-item>

              <el-form-item label="预计收益率">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.expectedYield"
                  class="width-90"
                  placeholder="请选择预计收益率"
                >
                  <el-option label="较高" value="90" />
                  <el-option label="中等" value="85" />
                  <el-option label="不详" value="75" />
                </el-select>
              </el-form-item>

              <el-form-item label="产业稳定性">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.industrialStability"
                  class="width-90"
                  placeholder="请选择产业稳定性"
                >
                  <el-option label="高" value="90" />
                  <el-option label="中等" value="85" />
                  <el-option label="不详" value="75" />
                </el-select>
              </el-form-item>

              <el-form-item label="资本额度">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.capitalLimit"
                  class="width-90"
                  placeholder="请选择资本额度"
                >
                  <el-option label="融资额五倍以上" value="90" />
                  <el-option label="五倍以下" value="80" />
                </el-select>
              </el-form-item>

              <el-form-item label="家庭实际收入">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.familyIncome"
                  class="width-90"
                  placeholder="请选择家庭实际收入"
                >
                  <el-option label="高" value="90" />
                  <el-option label="中等" value="85" />
                  <el-option label="不详" value="75" />
                </el-select>
              </el-form-item>

              <el-form-item label="其他收入">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.otherIncome"
                  class="width-90"
                  placeholder="请选择其他收入"
                >
                  <el-option label="有" value="90" />
                  <el-option label="无" value="80" />
                </el-select>
              </el-form-item>
            </el-scrollbar>
          </el-tab-pane>

          <el-tab-pane label="客户资产情况">
            <el-scrollbar style="height: 400px;">
              <el-form-item label="不动产估值">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.realEstateValuation"
                  class="width-90"
                  placeholder="请选择不动产估值"
                >
                  <el-option label="融资额五倍以上" value="90" />
                  <el-option label="五倍以下" value="80" />
                </el-select>
              </el-form-item>

              <el-form-item label="生产工具估值">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.instrumentValuation"
                  class="width-90"
                  placeholder="请选择生产工具估值"
                >
                  <el-option label="高" value="90" />
                  <el-option label="中等" value="85" />
                  <el-option label="不详" value="75" />
                </el-select>
              </el-form-item>

              <el-form-item label="银行存款">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.bankDeposit"
                  class="width-90"
                  placeholder="请选择银行存款"
                >
                  <el-option label="前三年平均额等于大于融资额" value="95" />
                  <el-option label="前三年平均额等于小于融资额" value="85" />

                </el-select>
              </el-form-item>

              <el-form-item label="无形资产、专利">
                <el-select v-model="dialog.add.form.userInfoProperty.patent" class="width-90" placeholder="请选择无形资产、专利">
                  <el-option label="有" value="90" />
                  <el-option label="无" value="80" />
                </el-select>
              </el-form-item>

              <el-form-item label="总资产">
                <el-select v-model="dialog.add.form.userInfoProperty.totalAssets" class="width-90" placeholder="请选择总资产">
                  <el-option label="融资额五倍以上" value="90" />
                  <el-option label="五倍以下" value="80" />
                </el-select>
              </el-form-item>
            </el-scrollbar>
          </el-tab-pane>

          <el-tab-pane label="客户征信情况">
            <el-scrollbar style="height: 400px;">
              <el-form-item label="对外担保比率">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.externalGuaranteeRatio"
                  class="width-90"
                  placeholder="请选择对外担保比率"
                >
                  <el-option label="担保比率小于10%" value="90" />
                  <el-option label="10%-30%" value="80" />
                  <el-option label="30%以上" value="60" />
                </el-select>
              </el-form-item>

              <el-form-item label="信誉评价">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.reputationEvaluation"
                  class="width-90"
                  placeholder="请选择信誉评价"
                >
                  <el-option label="好" value="90" />
                  <el-option label="良好" value="80" />
                  <el-option label="一般" value="60" />
                </el-select>
              </el-form-item>

              <el-form-item label="违法不良记录">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.illegalBadRecords"
                  class="width-90"
                  placeholder="请选择违法不良记录"
                >
                  <el-option label="无" value="95" />
                  <el-option label="有" value="60" />
                </el-select>
              </el-form-item>

              <el-form-item label="银行不良记录">
                <el-select
                  v-model="dialog.add.form.userInfoProperty.badBankRecords"
                  class="width-90"
                  placeholder="请选择银行不良记录"
                >
                  <el-option label="无" value="95" />
                  <el-option label="有" value="60" />
                </el-select>
              </el-form-item>
            </el-scrollbar>
          </el-tab-pane>
        </el-tabs>
      </el-form>

      <div v-if="dialog.add.editSwitch" slot="footer" class="dialog-footer text-center">
        <el-button @click="dialog.add.show = false">取 消</el-button>
        <el-button type="primary" @click="submitUserInfo()">确 定</el-button>
      </div>
    </el-dialog>

    <!--合同弹窗-->
    <el-dialog
      :close-on-click-modal="false"
      :title="dialog.contract.title"
      :visible.sync="dialog.contract.show"
      width="800px"
    >
      <el-form ref="form" :model="dialog.contract.form" label-width="120px">
        <p>合约书编号：
          <el-input
            v-if="!this.dialog.contract.previewSwitch && dialog.contract.row.contractStatus == '0'"
            v-model="dialog.contract.form.contractCode"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.contractCode || '--' }}</span>
        </p>
        <p>立合约书人：
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.createContractAuthor"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.createContractAuthor || '--' }}</span>
          保险代理人股份有限公司（以下称甲方）
        </p>
        <p>
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.contractSigner"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.contractSigner || '--' }}</span>
          先生/女士（以下称乙方）
        </p>
        <p>兹因乙方同意为甲方报告订立保险契约之机会，双方依诚实信用原则订立居间合约如下：</p>
        <h4>第一条&nbsp;合意事项</h4>
        <p>
          双方依本合约之约定成立居间关系，不适用其它劳务关系相关约定或规定，乙方同意
          为甲方寻觅及指示可与其签订保险契约之相对人，而提供签约之机会。
        </p>
        <h4>第二条&nbsp;居间报酬</h4>
        <p>
          保险契约因乙方之居间而成立生效，并逾契约撤销期限确定生效后，乙方始得按甲方
          之相关报酬标准支领报酬。
        </p>
        <h4>第三条&nbsp;合约期间</h4>
        <p>
          本合约自甲方完成相关程序并核定生效日起生效，乙方无异议同意以甲方核定之生效
          日为准。本合约以
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.contractCode"
            style="width: 100px"
          />
          <span v-else>XXXX</span>
          个月为一期，每期届满后一个月内如乙方无异议则视同续约。
        </p>
        <h4>第四条&nbsp;权利义务</h4>
        <p>
          双方同意遵守本合约之规定，乙方倘有违反本合约及其它相关办法之约定，或为本合
          约约定范围外之行为，致损及甲方或第三人权益时，应负损害赔偿责任。
        </p>
        <h4>第五条&nbsp;其它约定</h4>
        <p>
          本合约之条款及甲方所订其它相关办法均为本居间合约之构成部份。
        </p>
        <p>
          本合约未尽事宜，悉依中华民国相关法令规章办理。
        </p>
        <p>
          甲方：
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.createContractAuthor"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.createContractAuthor || '--' }}</span>
          保险代理人股份有限公司
        </p>
        <p>
          代表人：
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.representativePartyA"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.representativePartyA || '--' }}</span>
        </p>
        <p>
          通讯地址：
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.addressPartyA"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.addressPartyA || '--' }}</span>
        </p>
        <p>
          乙方：
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.contractSigner"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.contractSigner || '--' }}</span>
          （业务居间人)
        </p>
        <p>
          身份证字号：
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.iNumber"
            style="width: 200px"
          />
          <span v-else>{{ dialog.contract.form.iNumber || '--' }}</span>
        </p>
        <p>
          户籍地址：
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.address"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.address || '--' }}</span>
        </p>
        <p>
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.contractYear"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.contractYear || '--' }}</span>
          年
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.contractMonth"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.contractMonth || '--' }}</span>
          月
          <el-input
            v-if="!this.dialog.contract.previewSwitch"
            v-model="dialog.contract.form.contractDay"
            style="width: 100px"
          />
          <span v-else>{{ dialog.contract.form.contractDay || '--' }}</span>
          日
        </p>

      </el-form>

      <div slot="footer" class="dialog-footer text-center">
        <el-button
          v-show="dialog.contract.row.contractStatus == '0'"
          @click="dialog.contract.show = false"
        >取 消
        </el-button>
        <!--        <el-button-->
        <!--          v-show="dialog.contract.previewSwitch == false"-->
        <!--          type="primary"-->
        <!--          @click="dialog.contract.previewSwitch = true"-->
        <!--        >预 览-->
        <!--        </el-button>-->
        <!--        <el-button-->
        <!--          v-show="dialog.contract.previewSwitch == true && dialog.contract.row.contractStatus == '0'"-->
        <!--          type="primary"-->
        <!--          @click="dialog.contract.previewSwitch = false"-->
        <!--        >编 辑-->
        <!--        </el-button>-->
        <el-button
          v-show="dialog.contract.previewSwitch == false"
          type="primary"
          @click="saveContractInfo"
        >确 定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryUserInfo,
  queryUserInfoList,
  saveContractInfo,
  saveUserInfo,
  selectContractInfo,
  updateStatus,
  userInsuranceInfo
} from '@/api/customerInfo'

export default {
  name: 'CustomerInfo',
  data() {
    return {
      queryForm: {},

      table: {
        data: [],
        loading: false
      },

      dialog: {
        add: {
          title: '添加客户信息',
          loading: false,
          show: false,
          editSwitch: true,
          form: {
            userInfoProperty: {}
          }
        },
        contract: {
          title: '合同信息',
          loading: false,
          show: false,
          previewSwitch: false,
          form: {
            contractCode: ''
          },
          row: {}
        },
        insurancePolicy: {
          title: '保单信息',
          loading: false,
          show: false,
          form: {}
        }
      },

      customerType: '客户'
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.queryTable()
    },

    queryTable() {
      const params = Object.assign({}, this.queryForm)
      this.queryUserInfoList(params)
    },

    // 打开新增、编辑弹窗
    openAddDialog(row, editSwitch = true) {
      this.dialog.add.title = '新增客户'
      this.dialog.add.show = true
      this.dialog.add.editSwitch = editSwitch
      this.dialog.add.form = {
        userInfoProperty: {}
      }

      // 编辑
      if (row) {
        this.dialog.add.title = '编辑客户'
        this.queryUserInfo({ userId: row.userId })
      }
    },

    // 打开合同弹窗
    openContractDialog(row, previewSwitch = false) {
      this.dialog.contract.show = true
      this.dialog.contract.row = row
      this.dialog.contract.previewSwitch = previewSwitch

      if (previewSwitch || row) {
        this.selectContractInfo({ userInfoId: row.userId })
      }
    },

    // 打开保单窗口
    openInsurancePolicyDialog(row) {
      this.dialog.insurancePolicy.show = true
      this.userInsuranceInfo({ userInfoId: row.userId })
    },

    // 获取当前客户类型描述，清空保险产品
    changeCustomerType(value) {
      this.customerType = value === '企业' ? '法人' : '客户'
      this.$set(this.dialog.add.form, 'product', '')
    },

    // 提交用户信息
    submitUserInfo() {
      const json = JSON.stringify(this.dialog.add.form.userInfoProperty)
      const params = Object.assign({}, this.dialog.add.form)
      params.userInfoProperty = json

      // 计算评分
      params.userScore = ''
      // params.userScore = this.calculateScore(params)

      this.saveUserInfo(params)
    },

    // 计算分数
    calculateScore(params) {
      let score = 0
      // 获取评级指标
      const obj = JSON.parse(params.userInfoProperty)
      // 判断客户类型
      // 个人 年龄，学历，住房，婚姻，财产，家庭年实际收入，诚信度
      if (params.userType === '个人') {
        const {
          age, education, HousingSituation
          , maritalStatus, bankDeposit, familyIncome
          , reputationEvaluation
        } = obj

        const sum = Number(age || 0) + Number(education || 0) + Number(HousingSituation || 0) +
          Number(maritalStatus || 0) + Number(bankDeposit || 0) + Number(familyIncome || 0) + Number(reputationEvaluation || 0)
        score = sum / 7
      } else {
        // 企业 产业稳定性，诚信度，企业不良记录，不动产，企业年收入，收益率，资本额度
        const {
          industrialStability, reputationEvaluation, badBankRecords
          , realEstateValuation, familyIncome, expectedYield
          , totalAssets
        } = obj

        const sum = Number(industrialStability || 0) + Number(reputationEvaluation || 0) + Number(badBankRecords || 0) +
          Number(realEstateValuation || 0) + Number(familyIncome || 0) + Number(expectedYield || 0) + Number(totalAssets || 0)
        score = sum / 7
      }

      return score.toFixed(2)
    },

    // 审核资质
    examine(row) {
      this.$confirm(`该客户资质评分为${row.userScore}分，是否通过审核？`, '审核资质', {
        distinguishCancelAndClose: true,
        confirmButtonText: '通过',
        cancelButtonText: '不通过'
      })
        .then(() => {
          // 通过
          const params = { userInfoId: row.userId, userStatus: '1' }
          this.updateStatus(params)
        })
        .catch(action => {
          if (action === 'cancel') {
            // 不通过
            const params = { userInfoId: row.userId, userStatus: '2' }
            this.updateStatus(params)
          }
        })
    },

    // 查询客户信息
    async queryUserInfoList(params) {
      try {
        this.table.loading = true
        const res = await queryUserInfoList(params)
        this.table.data = res || {}
      } catch (e) {
        console.error(e)
      } finally {
        this.table.loading = false
      }
    },

    // 查询客户信息
    async queryUserInfo(params) {
      try {
        this.dialog.add.loading = true
        const res = await queryUserInfo(params)
        this.dialog.add.form = res
        const json = JSON.parse(res.userInfoProperty)
        this.$set(this.dialog.add.form, 'userInfoProperty', json)
      } catch (e) {
        console.error(e)
      } finally {
        this.dialog.add.loading = false
      }
    },

    // 修改审核状态
    async updateStatus(params) {
      try {
        this.table.loading = true
        await updateStatus(params)
        this.$message({ message: '操作成功！', type: 'success' })
      } catch (e) {
        console.error(e)
      } finally {
        this.table.loading = false
        this.queryTable()
      }
    },

    // 保存客户信息
    async saveUserInfo(params) {
      try {
        this.dialog.add.loading = true
        await saveUserInfo(params)
        this.$message({ message: '操作成功！', type: 'success' })
      } catch (e) {
        console.error(e)
      } finally {
        this.dialog.add.loading = false
        this.dialog.add.show = false
        this.queryTable()
      }
    },

    // 查询合同信息
    async selectContractInfo(params) {
      try {
        this.dialog.contract.loading = true
        const res = await selectContractInfo(params)
        this.dialog.contract.form = res || {}
      } catch (e) {
        console.error(e)
      } finally {
        this.dialog.contract.loading = false
      }
    },

    // 查询保单信息
    async userInsuranceInfo(params) {
      try {
        this.dialog.insurancePolicy.loading = true
        const res = await userInsuranceInfo(params)
        this.dialog.insurancePolicy.form = res
      } catch (e) {
        console.error(e)
      } finally {
        this.dialog.insurancePolicy.loading = false
      }
    },

    // 保存合同信息
    async saveContractInfo() {
      try {
        this.dialog.contract.loading = true
        const params = Object.assign({}, this.dialog.contract.form)

        params.usersInfoId = this.dialog.contract.row.userId

        await saveContractInfo(params)
        this.$message({ message: '操作成功！', type: 'success' })
      } catch (e) {
        console.error(e)
      } finally {
        this.dialog.contract.loading = false
        this.dialog.contract.show = false
        this.queryTable()
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.width-90 {
  width: 90%;
}

::v-deep .el-scrollbar__wrap {
  overflow: scroll;
  overflow-x: hidden !important;
  height: 100%;
}
</style>
